home *** CD-ROM | disk | FTP | other *** search
/ Deutsche Edition 1 / Deutsche Edition 1.iso / amok / 081-090 / amok81 / m2 / talkdemo / txt / talknarrator.mod < prev    next >
Text File  |  1993-11-04  |  5KB  |  209 lines

  1. IMPLEMENTATION MODULE TalkNarrator;
  2. (*$ LargeVars:=FALSE StackParms:=FALSE Volatile:=FALSE
  3.     LongAlign:=TRUE
  4.  *)
  5.  
  6. FROM SYSTEM    IMPORT    ADR, ADDRESS, CAST, LONGSET, SHIFT;
  7. FROM Arts    IMPORT    Assert,BreakPoint;
  8. FROM ExecD    IMPORT    MsgPort, MsgPortPtr, IOStdReq, IOStdReqPtr, write,read,quick,
  9.             aborted;
  10. FROM ExecL    IMPORT    WaitPort, DoIO, SendIO, GetMsg, ReplyMsg, OpenDevice,
  11.             CloseDevice,CreateMsgPort,DeleteMsgPort,CheckIO,
  12.             CreateIORequest,DeleteIORequest,WaitIO,AbortIO;
  13. FROM GraphicsD    IMPORT    DrawModes,DrawModeSet;
  14. FROM GraphicsL    IMPORT    SetAPen,SetBPen,Move,Draw,SetDrMd,PolyDraw,DrawEllipse;
  15. FROM Narrator    IMPORT    NewNarrator, NewNarratorPtr, NewMouth, NewMouthPtr,
  16.             Mouth,noWrite,NarratorFlags,NarratorFlagSet;
  17. FROM TalkErr    IMPORT    ShowErr;
  18. IMPORT TranslatorL;
  19. FROM String IMPORT Length;
  20. IMPORT TB:TalkBase;
  21.  
  22.  
  23. TYPE
  24.   Arr4=ARRAY[0..3] OF SHORTINT;
  25. CONST
  26.   audChanMasks=Arr4{0011L,0101L,1010L,1100L};
  27.  
  28. VAR
  29.   (*$ LongAlign:=TRUE *)
  30.   actPhonBuff:TB.Str255;
  31.   readport,
  32.   writeport:MsgPortPtr;
  33.   narr:NewNarratorPtr;
  34.   readNarrator: NewMouthPtr;
  35.  
  36.   (*$ LongAlign:=FALSE *)
  37.   oldb,
  38.   oldh:INTEGER;
  39.   first:=BOOLEAN{TRUE};
  40.  
  41.  
  42. PROCEDURE DrawMouth(width{6},height{7}:INTEGER);
  43. BEGIN
  44.   SetDrMd(TB.myRp,DrawModeSet{complement});
  45.   IF first THEN
  46.     first:=FALSE
  47.   ELSE (* alten Mund erst löschen *)
  48.     DrawEllipse(TB.myRp,TB.midX,TB.midY,oldb,oldh);
  49.     DrawEllipse(TB.myRp,TB.midX,TB.midY,oldb,oldh+2);
  50.   END;
  51.   oldb:=6*width; oldh:=height;
  52.   DrawEllipse(TB.myRp,TB.midX,TB.midY,oldb,oldh);
  53.   DrawEllipse(TB.myRp,TB.midX,TB.midY,oldb,oldh+2);
  54. END DrawMouth;
  55.  
  56.  
  57. PROCEDURE Translate():BOOLEAN;
  58. BEGIN
  59.   RETURN TranslatorL.Translate(ADR(TB.textBuff),Length(TB.textBuff),
  60.                   ADR(TB.phonBuff),SIZE(TB.phonBuff))=0;
  61. END Translate;
  62.  
  63.  
  64. PROCEDURE InitTalker;
  65. BEGIN
  66.   actPhonBuff:=TB.phonBuff;
  67.   WITH narr^ DO
  68.     rate:=TB.myNarr.rate;
  69.     pitch:=TB.myNarr.pitch;
  70.     mode:=TB.myNarr.mode;
  71.     sex:=TB.myNarr.sex;
  72.     volume:=TB.myNarr.volume;
  73.     sampFreq:=TB.myNarr.sampFreq;
  74.     f0Enthusiasm:=TB.myNarr.f0Enthusiasm;
  75.     f0Perturb:=TB.myNarr.f0Perturb;
  76.     f1Adj:=TB.myNarr.f1Adj;
  77.     f2Adj:=TB.myNarr.f2Adj;
  78.     f3Adj:=TB.myNarr.f3Adj;
  79.     a1Adj:=TB.myNarr.a1Adj;
  80.     a2Adj:=TB.myNarr.a2Adj;
  81.     a3Adj:=TB.myNarr.a3Adj;
  82.     articulate:=TB.myNarr.articulate;
  83.     centralize:=TB.myNarr.centralize;
  84.     avBias:=TB.myNarr.avBias;
  85.     afBias:=TB.myNarr.afBias;
  86.     priority:=TB.myNarr.priority;
  87.     centphon:=TB.centLabs[ORD(TB.myNarr.centphon)];
  88.   END;
  89. END InitTalker;
  90.  
  91. PROCEDURE ExtractNarr;
  92. BEGIN
  93.   WITH narr^ DO
  94.     TB.myNarr.rate:=rate;
  95.     TB.myNarr.pitch:=pitch;
  96.     TB.myNarr.mode:=mode;
  97.     TB.myNarr.sex:=sex;
  98.     TB.myNarr.volume:=volume;
  99.     TB.myNarr.sampFreq:=sampFreq;
  100.     TB.myNarr.f0Enthusiasm:=f0Enthusiasm;
  101.     TB.myNarr.f0Perturb:=f0Perturb;
  102.     TB.myNarr.f1Adj:=f1Adj;
  103.     TB.myNarr.f2Adj:=f2Adj;
  104.     TB.myNarr.f3Adj:=f3Adj;
  105.     TB.myNarr.a1Adj:=a1Adj;
  106.     TB.myNarr.a2Adj:=a2Adj;
  107.     TB.myNarr.a3Adj:=a3Adj;
  108.     TB.myNarr.articulate:=articulate;
  109.     TB.myNarr.centralize:=centralize;
  110.     TB.myNarr.avBias:=avBias;
  111.     TB.myNarr.afBias:=afBias;
  112.     TB.myNarr.priority:=priority;
  113.     TB.myNarr.centphon:=MIN(TB.CentrPhons); (* !! *)
  114.   END;
  115. END ExtractNarr;
  116.  
  117.  
  118. PROCEDURE AbortTalk();
  119. BEGIN
  120.   IF talking THEN
  121.     IF ~CheckIO(readNarrator) THEN
  122.       AbortIO(readNarrator);
  123.     END;
  124.     WaitIO(readNarrator);
  125.  
  126.     IF ~CheckIO(narr) THEN
  127.       AbortIO(narr);
  128.     END;
  129.     WaitIO(narr);
  130.     IF narr^.message.error#aborted THEN
  131.       ShowErr(narr^.message.error);
  132.     END;
  133.     talking:=FALSE;
  134.   END;
  135. END AbortTalk;
  136.  
  137. PROCEDURE DoTalk(testAbort:BoolProc);
  138. BEGIN
  139.   talking:=TRUE;
  140.   InitTalker;
  141.   WITH narr^ DO
  142.     message.error:=0;
  143.     mouths:=1;
  144.     message.data:=ADR(actPhonBuff); message.length:=Length(actPhonBuff)
  145.   END;
  146.   WITH readNarrator^.voice.message DO
  147.     device:=narr^.message.device;
  148.     unit:=narr^.message.unit;
  149.     command:=read;
  150.     error:=0
  151.   END;
  152.   readNarrator^.width:=0; readNarrator^.height:=0;
  153.   SendIO(narr);
  154.   LOOP
  155.     IF narr^.message.error#0 THEN
  156.       EXIT;
  157.     END;
  158.     DoIO(readNarrator);
  159.     IF readNarrator^.voice.message.error#0 THEN EXIT END;
  160.     DrawMouth(readNarrator^.width,readNarrator^.height);
  161.     IF testAbort() THEN EXIT END;
  162.   END;
  163.   AbortTalk;
  164.   talking:=FALSE;
  165. END DoTalk;
  166.  
  167.  
  168. BEGIN
  169.   writeport:=CreateMsgPort();
  170.   readport:=CreateMsgPort();
  171.   narr:=CreateIORequest(writeport,SIZE(narr^));
  172.   readNarrator:=CreateIORequest(readport,SIZE(readNarrator^));
  173.   Assert((readNarrator#NIL) AND (narr#NIL),ADR("no CreatextIO"));
  174.  
  175.   WITH narr^ DO
  176.     flags:=NarratorFlagSet{newIORB};
  177.     chMasks:=ADR(audChanMasks);
  178.     nmMasks:=SIZE(audChanMasks);
  179.     mouths:=1;
  180.     message.command:=write
  181.   END;
  182.   OpenDevice(ADR('narrator.device'),0,narr,LONGSET{});
  183.   ShowErr(narr^.message.error);
  184.   Assert(narr^.message.device#NIL,ADR('opendeverr'));
  185.   ExtractNarr;
  186.   TB.defNarr:=TB.myNarr;
  187.   DrawMouth(5,0);
  188. CLOSE
  189.   AbortTalk;
  190.   IF narr#NIL THEN
  191.     WaitIO(narr);
  192.     CloseDevice(narr);
  193.     DeleteIORequest(narr);
  194.     narr:=NIL
  195.   END;
  196.   IF readNarrator#NIL THEN
  197.     DeleteIORequest(readNarrator);
  198.     readNarrator:=NIL
  199.   END;
  200.   IF readport#NIL THEN
  201.     DeleteMsgPort(readport);
  202.     readport:=NIL;
  203.   END;
  204.   IF writeport#NIL THEN
  205.     DeleteMsgPort(writeport);
  206.     writeport:=NIL
  207.   END;
  208. END TalkNarrator.
  209.